package com.liujiaqi.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Component
//@Aspect
public class MyAspect6 {

  @Pointcut("execution(* com.liujiaqi.service.impl.DeptServiceImpl.*(..))")
  public void pt(){};

  @Before("pt()")
  public void before(JoinPoint joinPoint) {
    log.info("MyAspect6...before ...");
  }

  @Around("pt()")
  public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    log.info("MyAspect6...around before ...");

    // 1.获取 目标对象的类名
    String className = proceedingJoinPoint.getTarget().getClass().getName();
    log.info("目标对象的类名:{}", className);

    // 2.获取 目标方法的方法名
    String methodName = proceedingJoinPoint.getSignature().getName();
    log.info("目标方法的方法名:{}",methodName);

    // 3.获取 目标方法运行时传入的参数
    Object[] args = proceedingJoinPoint.getArgs();
    log.info("目标方法运行时传入的参数:{}",args);

    // 4.放行 目标方法执行
    Object result = proceedingJoinPoint.proceed();

    // 5.获取 目标方法运行的返回值
    log.info("目标方法运行的返回值:{}",result);

    log.info("MyAspect6...around after ...");
    return result;
  }

}
